import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_09: 分类歌单标签详情功能')
@allure.issue(
    'https://www.tapd.cn/56767367/sparrow/tcase/view/1156767367001043369?url_cache_key=17e362af8b12add5e45c5e468a11c15a')
class TestCaseMusic09:
    """
    预期结果: 正常进入分类详情列表
    """

    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()

        self.music_choice_page = CommonPage(self.driver).get_music_choice_page()
        self.music_index_page = CommonPage(self.driver).get_music_index_page()
        self.music_category_page = CommonPage(self.driver).get_music_category_page()
        self.music_category_detail_page = CommonPage(self.driver).get_music_category_detail_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('music')
        self.driver.quit()

    @allure.story("step1: 点击分类, 进入到分类页面")
    @pytest.mark.run(order=91)
    def test_music_09_1_click_category(self):
        try:
            # 进入音乐
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.MUSIC)
            if self.music_choice_page.is_display_title():
                self.music_choice_page.click_skip()
            
            self.music_index_page.click_category()
            time.sleep(2)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击任意分类标签, 查看是否进入分类标签的详情页面")
    @pytest.mark.run(order=92)
    def test_music_09_2_is_display_category_detail(self):
        try:
            self.music_category_page.click_list_tag_text()
            assert self.music_category_detail_page.is_display_list_music_cover()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    # pytest.main("-s testcase_05.py")
    pass
